<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: account.php 424 2014-01-19 11:37:19Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 424 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2014-01-19 11:37:19 +0000 (Sun, 19 Jan 2014) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */
define('GLOBAL_COLUMN_LEFT', '0');
include('includes/application_top.php');

$smarty = new Smarty();

require (DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/boxes.php');

require_once (DIR_FS_INC.'inc.count_customer_orders.php');
require_once (DIR_FS_INC.'inc.date_short.php');
require_once (DIR_FS_INC.'inc.build_order_id.php');

$breadcrumb->add(NAVBAR_TITLE_ACCOUNT, href_link(FILENAME_ACCOUNT, '', 'SSL'));

require(DIR_WS_INCLUDES.'header.php');

if(isset($_SESSION['tracking']['products_history'])) {
	$i = 0;
	$max = count($_SESSION['tracking']['products_history']);
	$row = 0;
	$list_data = get_list_data('history_product');

	while($i < $max) {
		$history_product = $db->db_query("SELECT
												*
											FROM
												".TABLE_PRODUCTS." p,
												".TABLE_PRODUCTS_DESCRIPTION." pd
											WHERE
												p.products_id = pd.products_id
											AND
												pd.language_id = '".(int) $_SESSION['languages_id']."'
											AND
												p.products_status = '1'
											AND
												p.products_id = '".$_SESSION['tracking']['products_history'][$i]."'");

		if ($history_product->_numOfRows) {
			while(!$history_product->EOF) { $row++;
				$cpath = get_product_path($_SESSION['tracking']['products_history'][$i]);
				$products = array_merge($history_product->fields, array('cat_url' => href_link(FILENAME_DEFAULT, 'cPath='.$cpath)));
				$module_content[] = $product->buildDataArray($products, 'thumbnail', $list_data, $row);
				$history_product->MoveNext();
			}
		}
		$i++;
	}
	
	if(!empty($module_content)) {
		$smarty->assign('module_content', $module_content);
		$smarty->assign('language', $_SESSION['language']);
		$smarty->assign('TITLE', HISTORY_PRODUCT);
		$smarty->assign('LIST_NAME', 'history_product');
		$smarty->assign('CLASS_NAME', 'grid');
		$module = $smarty->fetch(CURRENT_TEMPLATE.'/module/'.$list_data['list_file'].'.html');
		$smarty->assign('MODULE_products_history', $module);
	}
}

$order_content = '';
if(count_customer_orders() > 0) {
	$orders = $db->db_query_limit("SELECT
										o.orders_id,
										o.date_purchased,
										o.delivery_name,
										o.delivery_country,
										o.billing_name,
										o.billing_country,
										ot.text as order_total,
										s.orders_status_name
									FROM
										".TABLE_ORDERS." o, 
										".TABLE_ORDERS_TOTAL." ot, 
										".TABLE_ORDERS_STATUS." s
									WHERE
										o.customers_id = '".(int)$_SESSION['customer_id']."'
									AND
										o.orders_id = ot.orders_id
									AND
										ot.class = 'ot_total'
									AND
										o.orders_status = s.orders_status_id
									AND
										s.language_id = '".(int)$_SESSION['languages_id']."'
									ORDER BY
										orders_id DESC", 3);

	while(!$orders->EOF) {
		if (not_null($orders->fields['delivery_name'])) {
			$order_name = $orders->fields['delivery_name'];
			$order_country = $orders->fields['delivery_country'];
		} else {
			$order_name = $orders->fields['billing_name'];
			$order_country = $orders->fields['billing_country'];
		}
		$order_content[] = array ('ORDER_ID' => build_order_id($orders->fields['date_purchased'], $orders->fields['orders_id'], 'confirm'),
									'ORDER_DATE' => date_short($orders->fields['date_purchased']),
									'ORDER_STATUS' => $orders->fields['orders_status_name'],
									'ORDER_TOTAL' => $orders->fields['order_total'],
									'ORDER_LINK' => href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id='.$orders->fields['orders_id'], 'SSL'),
									'ORDER_BUTTON' => '<a href="'.href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id='.$orders->fields['orders_id'], 'SSL').'">'.image_button('small_view.gif', SMALL_IMAGE_BUTTON_VIEW).'</a>');
		$orders->MoveNext();
	}
}
$smarty->assign('LINK_EDIT', href_link(FILENAME_ACCOUNT_EDIT, '', 'SSL'));
$smarty->assign('LINK_ADDRESS', href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'));
$smarty->assign('LINK_PASSWORD', href_link(FILENAME_ACCOUNT_PASSWORD, '', 'SSL'));

if($_SESSION['customer_id'] != '1')
	$smarty->assign('LINK_DELETE', href_link(FILENAME_ACCOUNT_DELETE, '', 'SSL'));
	
if(!isset($_SESSION['customer_id']))
	$smarty->assign('LINK_LOGIN', href_link(FILENAME_LOGIN, '', 'SSL'));
	
$smarty->assign('LINK_ORDERS', href_link(FILENAME_ACCOUNT_HISTORY, '', 'SSL'));
$smarty->assign('LINK_NEWSLETTER', href_link(FILENAME_NEWSLETTER, '', 'SSL'));
$smarty->assign('LINK_ALL', href_link(FILENAME_ACCOUNT_HISTORY, '', 'SSL'));
$smarty->assign('order_content', $order_content);
if(isset($_SESSION['customer_id'])) {
	require_once(DIR_FS_INC.'inc.customer_greeting.php');
	$smarty->assign('greeting', sprintf(TEXT_GREETING_ACCOUNT, customer_greeting(false)));
}
$smarty->assign('also_purchased_history', $also_purchased_history);
$smarty->assign('language', $_SESSION['language']);
$smarty->caching = false;
$main_content = $smarty->fetch(CURRENT_TEMPLATE.'/module/account.html');

$smarty->assign('language', $_SESSION['language']);
$smarty->assign('main_content', $main_content);
$smarty->caching = false;
if(!defined('RM'))
	$smarty->loadFilter('output', 'note');
$smarty->loadFilter('output','trimwhitespace');
$smarty->display(CURRENT_TEMPLATE.'/index.html');
include ('includes/application_bottom.php');
?>